<template>
	<view class="page savepadding">
		<view class="card">
			<view class="title1">{{filterNull(schemeData.brandName)+" "+filterNull(schemeData.seriesName)}}</view>
			<view class="desc">{{filterNull(schemeData.modelName)}}</view>
		</view>
		<view class="card-title">订单信息</view>
		<view class="card">
			<view class="title">租赁信息</view>
			<view class="list inline">
				<view class="label">租赁方式<text style="color:red">*</text></view>
				<!-- <view class="text">{{formData.rentType|rentTypeText}}</view> -->
				<view class="text">{{filterNull(schemeData.schemeTypeStr)}}</view>
			</view>
			<view class="line"></view>
			<view class="list inline">
				<view class="label">租赁时长<text style="color:red">*</text></view>
				<view class="text">{{formData.tenancy}}期</view>
			</view>
		</view>
		<view class="card">
			<view class="title">付款方式</view>
			<view class="button-wrap">
				<view class="button" :class="{active:formData.paymentMethod==1, disable:!verifyTotalPrice(1)}"
					@click="setPaymentMethod(1)">按月支付</view>
				<view class="button" :class="{active:formData.paymentMethod==2, disable:!verifyTotalPrice(2)}"
					@click="setPaymentMethod(2)">两月支付</view>
				<view class="button" :class="{active:formData.paymentMethod==3, disable:!verifyTotalPrice(3)}"
					@click="setPaymentMethod(3)">季度支付</view>
				<view class="button" :class="{active:formData.paymentMethod==6, disable:!verifyTotalPrice(6)}"
					@click="setPaymentMethod(6)">半年支付</view>
				<view class="button" :class="{active:formData.paymentMethod==4, disable:!verifyTotalPrice(4)}"
					@click="setPaymentMethod(4)">按年支付</view>
				<view class="button" :class="{active:formData.paymentMethod==5, disable:!verifyTotalPrice(5)}"
					@click="setPaymentMethod(5)">一次性支付</view>
			</view>
			<view class="total" style="display:flex;">
				首期付款：<text>￥{{totalPrice}}元</text>
				<u-icon name="question-circle-fill" @click="showfeiyong1=true"></u-icon>
			</view>
			<view class="total" style="display:flex;">
				总合计：<text>￥{{fullPaymentShow.fullPayment}}元</text>
				<u-icon name="question-circle-fill" @click="showfeiyong2=true"></u-icon>
			</view>
		</view>
		<view class="card">
			<view class="title">还款方式</view>
			<u-radio-group v-model="formData.repaymentMethod" placement="column" activeColor="#12BAA4">
				<u-radio :customStyle="{marginBottom: '8px'}" label="其他还款方式" :name="2"></u-radio>
				<u-radio :customStyle="{marginBottom: '8px'}" label="微信支付" :name="1" v-if="orderConfValue==1"></u-radio>
				<template v-if="formData.rentType!=5 && daikouflag==1">
					<u-radio :customStyle="{marginBottom: '8px'}" label="自动代扣还款,省心省力" :name="3" @change="openxieyi"
						v-if="orderConfValue==1"></u-radio>
					<view class="blank-detail" v-if="isSigned" @click="goToWithholdDetail">已阅读并同意代扣协议</view>
				</template>
			</u-radio-group>
			<view class="line"></view>
			<view class="title">每期还款日期</view>
			<u-radio-group v-model="formData.paymentDayType" placement="column" activeColor="#12BAA4">
				<u-radio :customStyle="{marginBottom: '8px'}" label="还款日期与交车日期一致" :name="1"></u-radio>
				<u-radio :customStyle="{marginBottom: '8px'}" label="请选择还款日期" :name="2" @change="isDate=true"></u-radio>
				<view class="blank-detail" v-if="formData.paymentDayType==2" @click="isDate=true">
					每月{{formData.paymentDay}}日</view>
			</u-radio-group>
			<u-picker :show="isDate" :columns="days" @confirm="onconfirmData" @cancel="isDate=false"></u-picker>
		</view>
		<view class="card" style="height:226upx">
			<view class="title">订单备注</view>
			<template v-if="!showCoupon">
				<u--textarea v-model="formData.orderDesc" placeholder="请输入备注信息" count :maxlength="50"></u--textarea>
			</template>
		</view>
		<view class="card" @click="onClickYouhui">
			<view class="title" style="margin:0">
				<text v-if="formData.couponValue">{{couponData.couponName}} ￥{{couponData.money}}</text>
				<text v-else>选择优惠券</text>
				<u-icon name="arrow-right" />
			</view>
		</view>
		<view class="total" style="display:flex;">付款金额：<text>￥{{shijifukuan}}元</text>
			<u-icon name="question-circle-fill" @click="showfeiyong=true"></u-icon>
		</view>
		<view class="total" style="display:flex;" v-if="formData.couponValue">共省￥{{formData.couponValue}}</view>
		<view style="height:50px"></view>
		<!-- 按钮区 -->
		<view class="bottom_btns_wrap" style="background:#fff">
			<view class="bottom_btns savepadding">
				<view class="button" @click="pre">上一步</view>
				<!-- <view class="button" @click="submitOrder">立即支付</view> -->
				<view class="button" @click="onShowSubmitModel">{{formData.repaymentMethod==2?'提交订单':'立即支付'}}</view>
			</view>
		</view>
		<!-- 优惠券弹窗 -->
		<u-popup safeAreaInsetTop mode="bottom" :show="showCoupon" round="10" closeable @close="showCoupon=false">
			<CouponList v-if="showCoupon" :schemeTypeStr="schemeData.schemeTypeStr" :coupon="couponData"
				:rentType="formData.rentType" :carModelId="formData.carModelId" :feeItems="formData.feeItems"
				@selected="onCouponSelected"></CouponList>
		</u-popup>
		<!-- 提交订单提示 -->
		<u-modal :show="showSubmitModal" title="提交订单" :showCancelButton="true" :asyncClose="true" @confirm="submitOrder"
			@cancel="showSubmitModal=false">
			<view style="text-align:center">是否提交并支付订单</view>
		</u-modal>
		<!-- 费用信息弹窗1 -->
		<u-modal :show="showfeiyong1" title="首期付款金额明细说明" @confirm="showfeiyong1=false">
			<view>
				<template v-for="(item,index) in formData.feeItems">
					<view :key="index">{{item.type|feiyongFilter}}/元：￥{{item.amount}}/元</view>
				</template>
				<view>
					月租金*{{formData.paymentMethod|zhifufangshiFilter2(formData.tenancy)}}期￥{{fullPaymentShow.monthly_rent}}/元
				</view>
			</view>
		</u-modal>
		<!-- 费用信息弹窗2 -->
		<u-modal :show="showfeiyong2" title="总金额明细说明" @confirm="showfeiyong2=false">
			<view>
				<template v-for="(item,index) in fullPaymentShow.feeItems">
					<view :key="index">{{item.type|feiyongFilter}}/元：￥{{item.amount}}/元</view>
				</template>
				<view>月租金*{{formData.tenancy}}期￥{{fullPaymentShow.total}}/元</view>
			</view>
		</u-modal>
		<!-- 费用信息弹窗 -->
		<u-modal :show="showfeiyong" title="付款金额明细说明" @confirm="showfeiyong=false">
			<view>
				<template v-for="(item,index) in formData.feeItems">
					<view :key="index">{{item.type|feiyongFilter}}/元：￥{{item.amount}}/元</view>
				</template>
				<!-- <view>支付方式：{{formData.tenancy}}期 {{formData.paymentMethod|zhifufangshiFilter}}</view> -->
				<view>
					月租金*{{formData.paymentMethod|zhifufangshiFilter2(formData.tenancy)}}期￥{{fullPaymentShow.monthly_rent}}/元
				</view>
				<view v-if="formData.couponValue">优惠券抵扣金额/元：￥{{formData.couponValue}}/元</view>
			</view>
		</u-modal>
		<!-- 协议弹窗 -->
		<xieyi v-if="showxieyi" @ok="closexieyi"></xieyi>
		<!-- 登录弹窗 -->
		<LoginMask></LoginMask>
	</view>
</template>

<script>
	import sumBy from 'lodash/sumBy';
	import reduce from 'lodash/reduce';
	import isEmpty from 'lodash/isEmpty';
	import * as orderApi from '@/common/apis/order-api';
	import LoginMask from '@/components/layout/login-mask.vue';
	import CouponList from './components/coupon-list.vue';
	import xieyi from './components/xieyi.vue';
	import moment from '@/util/moment.js'

	export default {
		components: {
			LoginMask,
			CouponList,
			xieyi,
		},
		filters: {
			rentTypeText(rentType) {
				// 租赁类型：1、经租 2、以租代购 3、展示车 4、试驾车 5、融租 6、直购
				return {
					1: "经租",
					2: "以租代购",
					3: "展示车",
					4: "试驾车",
					5: "融租",
					6: "直购",
				} [rentType];
			},
			feiyongFilter(val) {
				return {
					cash_deposit: '保证金',
					servicing_fee: '整备费',
					down_payment: '首付款',
					monthly_rent: '月租',
					balance_payment: '尾款',
					advance_deposit: '定金',
					cover_charge: '服务费',
				} [val];
			},
			zhifufangshiFilter(val) {
				return {
					1: '月付',
					2: '两月付',
					3: '季度',
					4: '年付',
					5: '一次性结清',
					6: '半年付',
				} [val];
			},
			zhifufangshiFilter2(val, tenancy) {
				return {
					1: 1,
					2: 2,
					3: 3,
					4: 12,
					5: tenancy,
					6: 6,
				} [val];
			},
		},
		data() {
			return {
				showxieyi: false,
				showfeiyong1: false,
				showfeiyong2: false,
				showfeiyong: false,
				showSubmitModal: false,
				showCoupon: false,
				orderConfValue: 1, // 值为1时才显示代扣和微信支付
				daikouflag: 2, // 是否开通代扣1.开通 2.未开通
				couponData: {}, // 优惠券数据
				formData: {
					orderPaymentId: "", // 支付订单id（repaymentMethod为1时必传）
					carModelId: "", // 车型id
					rentType: 1, // 租赁类型：1、经租 2、以租代购 3、展示车 4、试驾车 5、融租 6、直购
					repaymentMethod: 2, // 还款方式：1.微信,2、其他，3、代扣
					paymentDayType: 1, // 每期还款日期：1、付款日与交车日一致 2、选择付款日
					paymentDay: 1, // 付款日（paymentDayType为2时必传，范围1-31正整数）
					orderDesc: "", // 订单备注（可以为空）
					paymentMethod: 5, // 付款方式 1、月付 2、两月付 3、季度 4、年付 5、一次性结清 6半年付
					tenancy: 36, // 租期
					couponNo: "", // 优惠券编号（可以为空）
					couponFaceValue: "", // 优惠券面额（可以为空）
					couponUseValue: "", // 优惠券使用金额（可以为空）
					couponValue: "", // 优惠券金额（可以为空）
					couponType: "", // 优惠券类型（可以为空）
					couponData: "", // 优惠券数据（可以为空）
					subSchemeId: "", // 子方案id
					feeItems: [ //费用项
						{
							amount: "", // 金额
							type: "", // 费用类型:
							// cash_deposit 保证金
							// servicing_fee 整备费
							// down_payment 首付款
							// monthly_rent 月租
							// balance_payment 尾款
							// advance_deposit 定金
							// cover_charge 服务费
						},
					]
				},
				isSigned: false, // 是否已签约
				isFirstSigned: false, // 是否首次签约
				oneSignedBank: {
					cardImgFront: "", // 银行卡正面
					cardImgBack: "", // 银行卡背面
					mobileNo: "", // 手机号
					bankCardNo: "", // 银行卡号
					bankDeposit: "" // 开户行
				},
				schemeData: {
					brandName: '',
					schemeId: '',
					seriesName: '',
					modelName: '',
					schemeTypeStr: '',
					schemeType: 0, //1.直购，2分期购车，3租赁 4.金融分期
					dataList: [],
					selectItem: 0,
				},
				monthly_rent: 0,
				isDate: false, // 是否按日期支付
				nextPage: 1, // 订单提交成功页面的选择
			};
		},
		computed: {
			openid() {
				return this.$store.state.user.openid;
			},
			days() {
				return [
					[1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27,
						28, 29, 30, 31
					]
					// [1, 5, 10, 15, 20, 25],
				];
			},
			// 实际付款金额
			shijifukuan() {
				const total = this.totalPrice - Number(this.formData.couponValue);
				return Math.ceil(total * 100) / 100;
			},
			// 全款展示
			fullPaymentShow() {
				// 月租金
				const monthly_rent = this.monthly_rent;
				// 租期
				const tenancy = this.formData.tenancy;
				// 总杂费
				const total = sumBy(this.formData.feeItems, val => val.amount) - monthly_rent;
				// 全款
				let fullPayment = total + (monthly_rent * tenancy);
				fullPayment = Math.ceil(fullPayment * 100) / 100;
				return {
					monthly_rent: this.totalPrice - total, // 净月费
					total: tenancy * monthly_rent, // 总月费
					feeItems: this.formData.feeItems, // 费用项
					fullPayment, // 全款
				};
			},
			// 总合计
			totalPrice() {
				// 月租金
				const monthly_rent = this.monthly_rent;
				// 总杂费
				const total = sumBy(this.formData.feeItems, val => val.amount) - monthly_rent;
				// 租期
				const tenancy = this.formData.tenancy;
				// 分期支付方式
				const paymentMethod = this.formData.paymentMethod;
				// 全款
				let fullPayment = total + (monthly_rent * tenancy);
				fullPayment = Math.ceil(fullPayment * 100) / 100;
				// 最终抛出金额方法
				const output = (_payment) => {
					const amount = _payment <= fullPayment ? _payment : fullPayment;
					// // 如果使用了优惠券
					// console.log(this.formData.couponValue)
					// if (Number(this.formData.couponValue) > 0) {
					//     console.log(amount - Number(this.formData.couponValue));
					//     return amount - Number(this.formData.couponValue); // 减去优惠券金额
					// }
					return Math.ceil(amount * 100) / 100;
				};
				// 一次性付清
				if (paymentMethod == 5) {
					return fullPayment;
				}
				// 月付
				if (paymentMethod == 1) {
					return output(total + monthly_rent);
				}
				// 两月付
				if (paymentMethod == 2) {
					return output(total + (monthly_rent * 2));
				}
				// 季付
				if (paymentMethod == 3) {
					return output(total + (monthly_rent * 3));
				}
				// 半年付
				if (paymentMethod == 6) {
					return output(total + (monthly_rent * 6));
				}
				// 年付
				if (paymentMethod == 4) {
					return output(total + (monthly_rent * 12));
				}
			},
			payFormData() {
				return {
					paymentMethod: this.formData.paymentMethod, // 付款方式 1、月付 2、两月付 3、季度 4、年付 5、一次性结清 6半年付
					tenancy: this.formData.tenancy, // 租期
					couponNo: this.formData.couponNo, // 优惠券编号（可以为空）
					couponFaceValue: this.formData.couponFaceValue, // 优惠券面额（可以为空）
					couponUseValue: this.formData.couponUseValue, // 优惠券使用金额（可以为空）
					couponValue: this.formData.couponValue, // 优惠券金额（可以为空）
					couponType: this.formData.couponType, // 优惠券类型（可以为空）
					couponData: this.formData.couponData, // 优惠券数据（可以为空）
					feeItems: this.formData.feeItems,
				};
			},
		},
		onLoad(option) {
			this.schemeData = JSON.parse(option.data);
			const feeItems = this.schemeData.dataList[this.schemeData.selectItem]; // 选择方案
			this.formData.carModelId = this.schemeData.modelId; // 车型id
			const rentType = {
				1: 6,
				2: 2,
				3: 1,
				4: 5,
			};
			this.formData.rentType = rentType[this.schemeData.schemeType]; // 租赁类型：1、经租 2、以租代购 3、展示车 4、试驾车 5、融租 6、直购
			this.formData.tenancy = feeItems.tenancy; // 租期
			this.formData.subSchemeId = feeItems.subSchemeId; // 子方案id
			const keyMap = {
				'deposit': 'cash_deposit', // cash_deposit 保证金
				'servicingFee': 'servicing_fee', // servicing_fee 整备费
				'downPayment': 'down_payment', // down_payment 首付款
				'monthlyRent': 'monthly_rent', // monthly_rent 月租
				'balance': 'balance_payment', // balance_payment 尾款
				// 'deposit': 'advance_deposit', // advance_deposit 定金
				'coverCharge': 'cover_charge', // cover_charge 服务费
			};
			this.formData.feeItems = reduce(feeItems, (pv, v, k) => {
				if (keyMap[k] && v) {
					if (k == 'monthlyRent') {
						// console.log('monthlyRent', v)
						this.monthly_rent = v;
					}
					//  经租只有月租和保证金 
					if (this.formData.rentType == 1 && (k == 'monthlyRent' || k == 'deposit' || k ==
						'coverCharge')) {
						pv.push({
							amount: v,
							type: keyMap[k],
						});
					}
					// 以租代购月租整备费和尾款 
					if (this.formData.rentType == 2 && (k == 'monthlyRent' || k == 'servicingFee' || k ==
							'balance')) {
						pv.push({
							amount: v,
							type: keyMap[k],
						});
					}
					// 融租月租首付款和尾款 
					if (this.formData.rentType == 5 && (k == 'monthlyRent' || k == 'downPayment' || k ==
						'balance')) {
						pv.push({
							amount: v,
							type: keyMap[k],
						});
					}
				}
				return pv
			}, []); //费用项
			// console.log('this.formData.feeItems', this.formData.feeItems)
		},
		async created() {
			await this.orderConf();
			await this.getDaiKouFlag();
			const result = await this.getOneSignedBank(); // 获取银行卡签约信息(判断是否已签约)
			// 判断是否首次签约
			if (result) {
				this.isFirstSigned = false; // 不是首次签约
			} else {
				this.isFirstSigned = true; // 是首次签约
			}
			uni.$on('getOneSignedBank', this.getOneSignedBank);
		},
		async onShow() {
			await this.getOneSignedBank();
		},
		methods: {
			/**
			 * 选择优惠券
			 */
			async onCouponSelected(item) {
				this.formData.couponNo = item.memberId || ""; // 优惠券编号（可以为空）
				this.formData.couponFaceValue = item.money || ""; // 优惠券面额（可以为空）
				this.formData.couponUseValue = item.conditionMoney || ""; // 优惠券使用金额（可以为空）
				this.formData.couponValue = item.money || ""; // 优惠券金额（可以为空）
				this.formData.couponType = item.useTypeNo || ""; // 优惠券类型（可以为空）
				this.formData.couponData = item.preferentialInfo || ""; // 优惠券数据（可以为空）
				this.couponData = item; // 暂存优惠券数据
				// this.showCoupon = false; // 关闭优惠券弹窗
			},
			async orderConf() {
				try {
					const result = await orderApi.orderConf();
					this.orderConfValue = result;
					return result;
				} catch (error) {
					uni.showToast({
						title: error,
						icon: 'error'
					});
				}
			},
			async getDaiKouFlag() {
				try {
					const result = await orderApi.getDaiKouFlag();
					this.daikouflag = result;
					return result;
				} catch (error) {
					uni.showToast({
						title: error,
						icon: 'error'
					});
				}
			},
			/**
			 * 获取银行卡签约信息(判断是否已签约)
			 */
			async getOneSignedBank() {
				try {
					const result = await orderApi.getOneSignedBank();
					if (!isEmpty(result)) {
						this.oneSignedBank = result; // 银行卡签约信息
						this.isSigned = true; // 已签约
						return true;
					} else {
						this.isSigned = false; // 未签约
						return false;
					}
				} catch (error) {
					console.error('获取失败：获取银行卡签约信息', error);
					// uni.showToast({ title: error, icon: 'error' });
					return false;
				}
			},
			// 支付
			async payOrder() {
				try {
					let result = await orderApi.payOrder(this.payFormData);
					this.formData.orderPaymentId = result.orderPaymentId;
					await this.requestPayment(result);
					return result;
				} catch (error) {

				}
			},
			// 取消支付
			async cancelPayOrder() {
				const result = await orderApi.cancelPayOrder({
					orderPaymentId: this.formData.orderPaymentId,
				});
				this.formData.orderPaymentId = "";
				return result;
			},

			async onShowSubmitModel() {
				// 如果是代扣
				if (this.formData.repaymentMethod == 3) {
					const result = await this.onDaikou(); // 银行卡签约检测
					if (!result) {
						return; // 未签约
					}
					this.nextPage = 2;
				}
				this.showSubmitModal = true;
			},

			// 提交订单
			async submitOrder() {
				this.showSubmitModal = false;
				this.nextPage = 1;
				// 如果是微信支付
				if (this.formData.repaymentMethod == 1) {
					this.payOrder().then(res => {
						if (res) {
							this.submitOrderHandle();
						}
					})
				};
				// 如果是其他方式支付
				if (this.formData.repaymentMethod == 2) {
					this.nextPage = 2;
					this.submitOrderHandle();
				}
				// 如果是其他方式支付
				if (this.formData.repaymentMethod == 3) {
					this.nextPage = 2;
					this.submitOrderHandle();
				}
			},
			async submitOrderHandle() {
				try {
					uni.showToast({
						title: '订单提交中...',
						icon: 'loading'
					});
					const result = await orderApi.submitOrder(this.formData);

					this.recordOrder(result);

					uni.reLaunch({
						url: `/pages/confirm_order/order-paySuccess?totalPrice=${this.totalPrice}&page=${this.nextPage}`, // 支付成功页面
					})
					return result;
				} catch (error) {
					uni.showToast({
						title: error,
						icon: 'error'
					});
				}
			},

			//下单操作记录
			async recordOrder(orderid) {
				console.log('进入操作记录了');

				let nowTimes = new Date().getTime();

				let duration = Math.round((nowTimes - getApp().globalData.taskStartTime) / 1000);

				//访问
				this.$store.dispatch('home/recordUse', {
					recordType: 4,
					recordOrderId: orderid,
					objRecordData: {
						durationTime: duration,
						recordTime: moment(nowTimes).format('YYYY-MM-DD HH:mm:ss'),
						price: this.shijifukuan,
					}
				})
			},

			async openxieyi() {
				this.showxieyi = true;
			},
			async closexieyi() {
				this.showxieyi = false;
				await this.onDaikou();
			},
			/**
			 * 选择代扣方法
			 */
			async onDaikou() {
				const result = await this.getOneSignedBank(); // 获取银行卡签约信息(判断是否已签约)
				// 如果未签约,则跳去签约页面
				if (!result) {
					// 验证实名
					const verifyRelaName = await this.$store.dispatch('app/verifyRelaName', {
						openid: this.openid, // openid
						redirect: '/pages/signContract/signContract', // 跳转地址
					});
					// 已实名的话直接跳转
					if (verifyRelaName) {
						uni.navigateTo({
							url: '/pages/signContract/signContract',
						});
					}

				}
				return result;
			},
			/**
			 * 去银行卡详情页
			 */
			async goToWithholdDetail() {
				const result = await this.getOneSignedBank(); // 获取银行卡签约信息(判断是否已签约)
				// 如果未签约,则跳去签约页面
				if (!result) {
					uni.navigateTo({
						url: '/pages/withholdDetail/withholdDetail',
					});
				}
				return result;
			},
			/**
			 * 调起微信支付
			 */
			async requestPayment(value) {
				return new Promise((resolve, reject) => {
					uni.getProvider({
						service: 'payment',
						success: ({
							provider
						}) => {
							uni.requestPayment({
								provider: provider[0],
								orderInfo: value.orderPaymentId,
								timeStamp: value.timeStamp,
								nonceStr: value.nonceStr,
								package: value.package,
								signType: value.signType,
								paySign: value.paySign,
								success: res => {
									console.log('success:requestPayment', res);
									resolve(true);
								},
								fail: err => {
									console.log(err);
									uni.showToast({
										title: '支付失败',
										icon: 'error'
									});
									this.cancelPayOrder(); // 取消支付订单
									reject(false);
								},
								complete: res => {
									console.log('complete:requestPayment', res);
								}
							})
						}
					})
				})
			},

			pre() {
				uni.navigateBack()
			},

			/**
			 * 设置还款方式
			 */
			setPaymentMethod(paymentMethod) {
				if (this.verifyTotalPrice(paymentMethod)) {
					this.formData.paymentMethod = paymentMethod;
				}
			},

			/**
			 * @param {number} paymentMethod 分期支付方式
			 */
			verifyTotalPrice(paymentMethod) {
				// 月租金
				const monthly_rent = this.monthly_rent;
				// 总杂费
				const total = sumBy(this.formData.feeItems, val => val.amount) - monthly_rent;
				// 租期
				const tenancy = this.formData.tenancy;
				// 全款
				const fullPayment = total + (monthly_rent * tenancy);

				function output(_payment) {
					// console.log('verifyTotalPrice', _payment, fullPayment)
					return _payment <= fullPayment ? true : false;
				};
				// 一次性付清
				if (paymentMethod == 5) {
					return fullPayment;
				}
				// 月付
				if (paymentMethod == 1) {
					return output(total + monthly_rent);
				}
				// 两月付
				if (paymentMethod == 2) {
					return output(total + (monthly_rent * 2));
				}
				// 季付
				if (paymentMethod == 3) {
					return output(total + (monthly_rent * 3));
				}
				// 半年付
				if (paymentMethod == 6) {
					return output(total + (monthly_rent * 6));
				}
				// 年付
				if (paymentMethod == 4) {
					return output(total + (monthly_rent * 12));
				}
			},

			onconfirmData({
				value
			}) {
				this.formData.paymentDay = value[0];
				this.isDate = false;
			},

			onClickYouhui() {
				// uni.showToast({ title: '暂无可用优惠券', icon: 'error' });
				this.showCoupon = true;
			},

			// yuezujisuanqi(monthly_rent){
			//     // 分期支付方式
			//     const paymentMethod = this.formData.paymentMethod;
			// },

		}
	}
</script>

<style lang="scss" scoped>
	.page {
		padding: $page_padding;
		padding-bottom: 120upx;
	}

	.card-title {
		font-size: 32upx;
		font-weight: bold;
		margin-bottom: 30upx;
		margin-left: 40upx;
	}

	.card {
		padding: 40upx 40upx;
		margin-bottom: 30upx;

		.title1 {
			font-size: 28upx;
			font-weight: bold;
			color: #333;
			margin-bottom: 27upx;
		}

		.title {
			font-size: 32upx;
			font-weight: bold;
			color: #333;
			margin-bottom: 29upx;
			display: flex;
			justify-content: space-between;
			align-content: center;
		}

		.desc {
			font-size: 28upx;
			font-weight: bold;
			color: #999;
		}

		.line {
			margin-bottom: 30upx;
			border-bottom: 1px solid #ddd;
		}

		.list {
			&.inline {
				display: flex;
				justify-content: space-between;
			}

			.label {
				margin-bottom: 30upx;
				font-size: 28upx;
				font-weight: bold;
				color: #333;
			}

			.text {
				font-size: 28upx;
				font-weight: bold;
				color: #999;
			}
		}

		.button-wrap {
			display: flex;
			flex-wrap: wrap;
			justify-content: space-between;

			.button {
				width: 180upx;
				line-height: 66upx;
				text-align: center;
				font-size: 28upx;
				font-weight: bold;
				color: #333;
				border: 1px solid #12baa4;
				border-radius: 10px;
				margin-bottom: 20upx;

				&:not(:nth-child(3n + 0)) {
					margin-right: 20upx;
				}

				&.active {
					background: #12baa4;
					color: #fff;
				}

				&.disable {
					background: #ddd;
					color: #999;
					border-color: #ddd;
				}
			}
		}
	}

	.total {
		font-size: 28upx;
		font-weight: bold;

		text {
			font-size: 28upx;
			font-weight: bold;
			color: #12baa4;
		}
	}

	.bottom_btns {
		display: flex;
		justify-content: space-between;
		align-items: center;
		text-align: center;

		&_wrap {
			position: fixed;
			bottom: 0;
			left: 0;
			width: 100%;
			z-index: 10;
		}

		.button {
			flex: 1;
			line-height: 96upx;
			font-weight: bold;
		}

		.button:nth-child(1) {
			background: #fff;
			color: #666;
		}

		.button:nth-child(2) {
			background: #12baa4;
			color: #fff;
		}
	}

	.blank-detail {
		font-size: 24upx;
		margin-left: 50upx;
		margin-bottom: 8px;
		color: #333;
	}
</style>
